/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.iscte.iul.dcti.pa.gspas.util;

import java.util.List;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Gedsimon Pereira - 58554
 * @contact gspas@iscte.pt
 *
 */
public class CreateComponentGUI {

    public CreateComponentGUI() {
    }

    public static JPanel createGUI(JPanel panel, Class<?> object) {
        List<Property> properties = Property.getProperties(object);

        for (Property property : properties) {
            switch (property.getType()) {
                case BOOLEAN:
                    panel.add(createLabel(property.getLabel()));
                    panel.add(createBoolean("", true));
                    break;
                case INT:
                    panel.add(createLabel(property.getLabel()));
                    panel.add(createTxtField());
                    break;
                case DOUBLE:
                    panel.add(createLabel(property.getLabel()));
                    panel.add(createTxtField());
                    break;
                case ENUM:
                    break;
                case STRING:
                    panel.add(createLabel(property.getLabel()));
                    panel.add(createTxtField());
                    break;
                case COLLECTION:
                    panel.add(createLabel(property.getLabel()));
                    break;
                case COMPLEX:
                    //panel.add(createButton(property.getLabel()));
                    //panel.add(createLabel(""));
                    break;
                default:
                    break;
            }
        }
        panel.setLayout(new java.awt.GridLayout(properties.size(), 2, 5, 5));

        return panel;
    }

    /**
     *
     * @param name
     * @param state
     * @return A boolean component
     */
    public static JCheckBox createBoolean(String name, boolean state) {
        JCheckBox tmpCheckBox = new javax.swing.JCheckBox();
        tmpCheckBox.setText(name);
        tmpCheckBox.setSelected(state);
        return tmpCheckBox;
    }

    /**
     *
     * @param name
     * @return A label component
     */
    public static JLabel createLabel(String name) {
        JPanel tempPanel = new javax.swing.JPanel();
        tempPanel.setLayout(new java.awt.GridLayout(1, 1));
        JLabel tmpLabel = new javax.swing.JLabel();
        tmpLabel.setText(name);
        tempPanel.add(tmpLabel);
        return tmpLabel;
    }

    public static JTextField createTxtField() {
        JTextField tmpField = new javax.swing.JTextField();
        return tmpField;
    }

    public static JButton createButton(String name) {
        javax.swing.JButton tmpButton = new JButton();
        tmpButton.setText(name);
        return tmpButton;
    }
}
